package com.hailiao.beidou.message.ui.page.setting.view

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.d10ng.compose.ui.AppColor
import com.d10ng.compose.ui.AppText
import com.d10ng.compose.ui.base.CellRow
import com.hailiao.beidou.message.R

/**
 * 设置列表项
 * @Author d10ng
 * @Date 2023/11/14 17:46
 */
@Composable
fun SettingCell(
    iconId: Int,
    label: String,
    description: String = "",
    rightArrow: Boolean = true,
    onClick: () -> Unit = {},
    right: @Composable RowScope.() -> Unit = {}
) {
    CellRow(
        modifier = Modifier.height(80.dp).clickable { onClick() },
        divider = true,
        dividerPaddingValues = PaddingValues(start = 66.dp, end = 19.dp),
        contentPaddingValues = PaddingValues(horizontal = 19.dp)
    ) {
        Image(
            painter = painterResource(id = iconId),
            contentDescription = label,
            modifier = Modifier
                .padding(end = 12.dp)
                .size(35.dp)
        )
        Column {
            Text(text = label, style = AppText.Normal.Title.default)
            if (description.isNotEmpty()) {
                Text(text = description, style = AppText.Normal.Tips.mini)
            }
        }
        Spacer(modifier = Modifier.weight(1f))
        right()
        if (rightArrow) {
            Icon(
                painter = painterResource(id = R.drawable.cell_right_arrow),
                contentDescription = null,
                modifier = Modifier
                    .width(9.dp)
                    .height(16.dp),
                tint = AppColor.Neutral.tips
            )
        }
    }
}

@Composable
fun SettingCellText(
    iconId: Int,
    label: String,
    description: String = "",
    text: String = "",
    rightArrow: Boolean = true,
    onClick: () -> Unit = {},
) {
    SettingCell(
        iconId = iconId,
        label = label,
        description = description,
        rightArrow = rightArrow,
        onClick = onClick,
        right = {
            Text(
                text = text,
                style = AppText.Normal.Tips.default,
                modifier = Modifier.padding(end = 11.dp)
            )
        }
    )
}